$(function () {
    "use strict";//用严格模式运行

    /*个人信息*/
    $.ajax({
        url: 'PersonalPage/getuserinfo',
        type: 'post',
        success: function (result) {
            $.each(result.data, function (key, value) {
                $('.personal-nav-list li').eq(0).find('strong').text(value.moodnum);
                $('.personal-nav-list li').eq(1).find('strong').text(value.following);
                $('.personal-nav-list li').eq(2).find('strong').text(value.followed);
                if ($('.personal-nav-list li').eq(3).length > 0) {
                    $('.personal-nav-list li').eq(3).find('strong').text(value.moodsc);
                }
            });
        }
    });
    //判断文本框字数
    $(".send-weblog .send-box-textarea").on("input", function () {
        var num = $(this).val().length;
        $('.counter').html(140 - num);
        if (num === 0 || num > 140) {
            $("#send-box-btn").attr("disabled", "disabled");
        } else {
            $("#send-box-btn").removeAttr("disabled");
        }
    });
    //判断文本框字数2
    $("#global-send-box .send-box-textarea").on("input", function () {
        var num = $(this).val().length;
        $('.counter').html(140 - num);
        if (num === 0 || num > 140) {
            $("#send-box-btn2").attr("disabled", "disabled");
        } else {
            $("#send-box-btn2").removeAttr("disabled");
        }
    });

    //搜索下拉框
    $(".search-input").on("click", function (event) {
        event.stopPropagation();
        event.preventDefault();
        $(".search-input").on("input", function () {
            var isinput = $(this).val().length;
            var data = $(this).val();
            if (isinput > 0) {
                $.ajax({
                    url: 'Getuserinfo/getuserinfo',
                    type: 'post',
                    data: {
                        info: data
                    },
                    error: function () {
                        $(".search-form .dropdown-menu").hide();
                    },
                    success: function (result) {
                        if (result.data == '') {
                            $(".search-form .dropdown-menu").hide();
                        } else {
                            var html = '';
                            $.each(result.data, function (key, value) {
                                html += '<li class="per-item"><a class="js-nav" id="' + value.id + '" href="' + value.username + '"><img class="avatar size32" src="' + value.avatar + '"><span class="user-item-info"><span class="fullname">' + value.nickname + '</span>@<span class="username">' + value.username + '</span></span></a></li>';
                            });
                            $('#search-per-info').html(html);
                            $(".search-form .dropdown-menu").show();
                        }
                    }
                });
            } else {
                $(".search-form .dropdown-menu").hide();
            }
        });
        var closeDropDown = function () {
            $(".search-form .dropdown-menu").hide();
            $(document).off('click', closeDropDown);
        };
        $(document).on('click', closeDropDown);
    });


    $('.nav-search').on('click', function () {
        var i = $('#search-per-info').eq(0);
        var h = i.find('.js-nav').attr('href');
        if (h != '' && h != undefined) {
            window.location.href = h;
        }
    });
    $('.search-input').on('keydown', function (e) {
        if (e.keyCode == '13') {
            var i = $('#search-per-info').eq(0);
            var h = i.find('.js-nav').attr('href');
            if (h != '' && h != undefined) {
                window.location.href = h;
            }
        }
    });

    //个人信息下拉框
    $(".me-btn").on("click", function (event) {
        event.stopPropagation();//停止事件冒泡
        event.preventDefault();//阻止默认事件
        $(".right-action .dropdown-menu").show();
        var closeDropDown = function () {
            $(".right-action .dropdown-menu").hide();
            $(document).off('click', closeDropDown);
        };
        //setTimeout(function () {
        //    $(document).on('click', closeDropDown);
        //}, 1);/*放到事件队列的最后*/
        $(document).on('click', closeDropDown);
    });

    //send WebLog dialog hide &&show
    $(".modal-close").on("click", function () {
        $('#global-send-box').css("display", "none");
        $('#global-repeat-box').css("display", "none");
        $(".global-dialog").hide();
    });
    $(".bianji-btn").on("click", function () {
        $('#global-send-box').css('display', "block");
        $(".global-dialog").show();
    });



    //todo
    //判断显示图片
    //$(".stream-item-avater").on();

    ///* todo get personal info */
    //$.ajax({
    //    url: 'PersonalInfo/getpersonalinfo',
    //    type: 'post',
    //    success: function (result) {
    //        $.each(result.data, function (key, value) {
    //            var html = '';
    //        });
    //    }
    //});

});